using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace ICP_MS.Plugin.Experiment.Forms;

public class TimingMessageBox : Form
{
	private int second;

	private int counter;

	private IContainer components = null;

	private Button buttonOK;

	private Label labelMessage;

	private Timer timer1;

	public TimingMessageBox(string message, int second)
	{
		InitializeComponent();
		labelMessage.Text = message;
		this.second = second;
		counter = 0;
		buttonOK.Text = $"取消({this.second - counter})";
		timer1.Enabled = true;
		timer1.Interval = 1000;
		timer1.Start();
	}

	private void timer1_Tick(object sender, EventArgs e)
	{
		if (counter <= second)
		{
			buttonOK.Text = $"取消({second - counter})";
			Refresh();
			counter++;
		}
		else
		{
			timer1.Enabled = false;
			timer1.Stop();
			base.DialogResult = DialogResult.OK;
			Close();
		}
	}

	private void buttonOK_Click(object sender, EventArgs e)
	{
		base.DialogResult = DialogResult.Cancel;
		Close();
	}

	private void TimingMessageBox_Load(object sender, EventArgs e)
	{
		Win32API.SetTopMost((Control)this);
		Focus();
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.components = new System.ComponentModel.Container();
		this.buttonOK = new System.Windows.Forms.Button();
		this.labelMessage = new System.Windows.Forms.Label();
		this.timer1 = new System.Windows.Forms.Timer(this.components);
		base.SuspendLayout();
		this.buttonOK.Location = new System.Drawing.Point(232, 138);
		this.buttonOK.Name = "buttonOK";
		this.buttonOK.Size = new System.Drawing.Size(87, 41);
		this.buttonOK.TabIndex = 0;
		this.buttonOK.Text = "取消";
		this.buttonOK.UseVisualStyleBackColor = true;
		this.buttonOK.Click += new System.EventHandler(buttonOK_Click);
		this.labelMessage.AutoSize = true;
		this.labelMessage.Font = new System.Drawing.Font("宋体", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
		this.labelMessage.Location = new System.Drawing.Point(43, 74);
		this.labelMessage.Name = "labelMessage";
		this.labelMessage.Size = new System.Drawing.Size(0, 20);
		this.labelMessage.TabIndex = 1;
		this.timer1.Interval = 1000;
		this.timer1.Tick += new System.EventHandler(timer1_Tick);
		base.AutoScaleDimensions = new System.Drawing.SizeF(8f, 15f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(364, 199);
		base.Controls.Add(this.labelMessage);
		base.Controls.Add(this.buttonOK);
		base.MaximizeBox = false;
		base.MinimizeBox = false;
		base.Name = "TimingMessageBox";
		base.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
		this.Text = "提示";
		base.Load += new System.EventHandler(TimingMessageBox_Load);
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
